/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.tkgarment.system.action;


import com.tkgarment.system.dao.EmpTypeDAO;
import com.tkgarment.system.domain.EmployeeType;
import com.tkgarment.system.factory.DAOFactory;
import java.util.Map;
import org.apache.struts2.interceptor.SessionAware;

/**
 *
 * @author zraj
 */
public class EmpTypeAction extends ActionSupportBase implements SessionAware {

    private Map<String, Object> session;
    private EmployeeType empType;
    
    
    public String deleteEmpType() throws Exception {
        
        EmpTypeDAO dao = DAOFactory.createEmpTypeDao();
        int i = dao.deleteSingle(empType);
        
        if (i == 1) {
            setMessage("ลบข้อมูลเรียบร้อยแล้ว");
            return "success";
        } else if(i == 99) {
            setMessage("ไม่สามารถลบข้อมูลได้ ข้อมูลนี้มีการใช้งานอยู่");
            return "success";
        }else{
            return ERROR;
        }
        
        
    }
    
    
    
    public String formEditEmpType() throws Exception {
        
        EmpTypeDAO dao = DAOFactory.createEmpTypeDao();
        setEmpType(dao.getEmpTypeByID(empType.getEmpTypeID()));
        
        return "success";
    }
    
    
    public String addEmpType() throws Exception {
        
        EmpTypeDAO dao = DAOFactory.createEmpTypeDao();
        
        int  i = dao.insertSingle(empType);
        if (i == 1) {
          return "success";    
        }else
        {
          return ERROR; 
        }
        
        
    }
    
    
    public String formAddEmpType() throws Exception {
        return "success";
    }
    
    
    public String execute() throws Exception {
        return "success";
    }

    public EmployeeType getEmpType() {
        return empType;
    }

    public void setEmpType(EmployeeType empType) {
        this.empType = empType;
    }
    
    
    
    
    
    public Map<String, Object> getSession() {
        return session;
    }
    
    
    
    @Override
    public void setSession(Map<String, Object> map) {
        this.session = map;
    }
    
}
